/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package CreateTable;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author tashiba
 */
public class CreateTableGolonganUmur {
    public static void main(String[] args) {

        try {
            try {
                Class.forName("com.mysql.jdbc.Driver");
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(CreateTableUser.class.getName()).log(Level.SEVERE, null, ex);
            }
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/pti", "root", "115314034");


            System.out.println("Koneksi is OK");
            Statement statement = conn.createStatement();
            String golUmur = " CREATE TABLE GOLONGANUMUR (IDGOLUMUR VARCHAR(15) NOT NULL,"
                    + "GOLUMUR VARCHAR(20) NOT NULL,"
                    + "CONSTRAINT GOLONGANUMUR_PK PRIMARY KEY(IDGOLUMUR));";

            statement.executeUpdate(golUmur);
            System.out.println("Tabel GOLONGAN UMUR Created");
            
            ResultSet rs = null;
            PreparedStatement pst = null;

            String sql = "insert into golonganumur (idgolumur, golumur) "
                    + "values ('Umr1', '0-28 Hari'),('Umr2','28 Hari - 1 Tahun'),"
                    + "('Umr3','1 - 4 Tahun'),('Umr4','5 - 14 Tahun'),"
                    + "('Umr5','15 - 24 Tahun'),('Umr6','25 - 44 Tahun'),"
                    + "('Umr7','44 - 64 Tahun'),('Umr8','65++')";

            pst = conn.prepareStatement(sql);
            pst.execute();
            System.out.println("data berhasil ditambahkan");
        } catch (SQLException e) {
// perform error handling here
            System.out.println("error :" + e.getMessage());
        }
    }
}
